package com.hospital.dao;

import com.hospital.domain.DoctorSit;
import com.hospital.domain.Register;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DoctorSitDao {
    @Select("select * from doctorinfo,doctorsitinfo,sitinforinfo" +
            " where doctorinfo.doctorID = #{doctorID} and sitinforinfo.sitinforID = doctorsitinfo.sitID " +
            "and doctorinfo.doctorID = doctorsitinfo.doctorID and `date` > current_date()")
    public List<DoctorSit> selectDoctorDitByDoctorID(int doctorID);


    @Update("update doctorsitinfo set remainNum = #{remainNum} " +
            " where doctorID = #{doctorID} and sitID = #{sitID}")
    public int subRemain(DoctorSit doctorSit);

    @Update("UPDATE doctorsitinfo SET remainNum = remainNum + 1 \n" +
            "WHERE doctorsitinfo.doctorID = #{doctorID} AND sitID = \n" +
            "(SELECT DISTINCT sitInforID FROM registinfo,sitinforinfo WHERE userID = #{userID} " +
            "AND registinfo.doctorID = doctorsitinfo.doctorID " +
            "AND registinfo.`date` = #{date}\n" +
            "AND registinfo.`AMorPM` = #{amorPM} " +
            "AND registinfo.`dayOfWeek` = #{dayOfWeek}\n" +
            " AND registinfo.`date` = sitinforinfo.`date`\n" +
            "AND registinfo.`AMorPM` = sitinforinfo.`AMorPM` \n" +
            "AND registinfo.`dayOfWeek` = sitinforinfo.`dayOfWeek`)")
    public int addRemain(Register register);

    @Insert("insert into doctorsitinfo values (#{doctorID},#{sitID},#{remainNum},#{allNum})")
    public Integer addDoctorSit(DoctorSit doctorSit);


    @Select("select * from doctorSitinfo where doctorID=#{doctorID} and sitID=#{sitID}")
    public DoctorSit selectDoctorSitBySitIDAndDoctorID(@Param("doctorID") int doctorID,@Param("sitID") int sitID);

    public List<DoctorSit> selectDoctorSit(String doctorName);

}
